<%--
    Document   : index
    Created on : Oct 11, 2011, 12:01:14 AM
    Author     : XuanTuan
--%>

<%@page import="java.io.FileInputStream"%>
<%@page import="model.CA_Service"%>
<%@page import="model.CertificateDAO"%>
<%@page import="model.Certificate"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>VeriSign Authentication Services - The leading Provider of SSL.
            Products include SSL, SSL Certificates, Extended Validation
            (EV SSL), VeriSign Trust Seal, Malware Scan & Code Signing.</title>
        <link href="styles.css" rel="stylesheet" type="text/css" media="screen" />
        <link rel="stylesheet" href="nivo-slider.css" type="text/css" media="screen" />

        <script type="text/javascript">
            function areYouSure(){
                return confirm("Are you sure?");
            }
        </script>

        <style type="text/css">
            #right table tr{
                height: 35px;
            }
        </style>
    </head>
    <body>
        <div id="content">
            <div class="header_text">
                <div id="logo" >
                    <img src="images/verisignLogo.gif"/>
                </div>
            </div>
            <div id="back">
                <!-- header begins -->
                <div id="header">
                    <%@ include file="header.jsp" %>
                </div>
                <!-- header ends -->
                <!-- content begins -->
                <div id="main">
                    <div id="right">
                        <%
                                    String user2 = (String) session.getAttribute("user");
                                    if (user2 != null) {
                        %>

                        <h1>Manager Certificates</h1><br/>
                        <%
                                                                ArrayList<Certificate> array = CertificateDAO.getCertByUser(user2);
                        %>
                        <table width="500" border="1">
                            <tr bgcolor="" align="center" style="font-weight: bolder;font-size: 1.2em;">
                                <td>Serial Num</td>
                                <td>Date create</td>
                                <td>Date expire</td>
                                <td>Status</td>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td><a>Detail</a></td>
                            </tr>
                            <%
                                                                    for (int idx = 0; idx < array.size(); idx++) {
                                                                        Certificate elem = array.get(idx);
                                                                        String status = "";
                                                                        if (!CA_Service.validateCert((new FileInputStream(elem.getCertPath())))) {
                                                                            status = "Expired";
                                                                        } else {
                                                                            status = elem.getStatus();
                                                                        }
                            %>
                            <tr align="center">
                                <td><%=elem.getSerial()%></td>
                                <td><%=elem.getNot_before().toString()%></td>
                                <td><%=elem.getNot_after().toString()%></td>
                                <td><%=status%></td>
                                <%
                                                                                                        if (!status.equals("In use")) {
                                %>
                                <td></td>
                                <td></td>
                                <td></td>
                                <td><a href="CertDetail.jsp?certPath=<%=elem.getCertPath()%>">Detail</a></td>
                                <%
                                                                                                                                        } else {
                                %>
                                <td>
                                    <a href="UpdateCert.jsp?certPath=<%=elem.getCertPath()%>"><img src="images/update.png" title="Update"/></a>
                                </td>
                                <td>
                                    <form action="RevokeCertControl">
                                        <!--                                        <img src="images/delete.png" title="Revoke"/>-->
                                        <input type="image" src="images/delete.png" title="Revoke" onclick="return areYouSure()">
                                        <input type="hidden" value="<%=elem.getCertPath()%>" name="certPath">
                                    </form>

                                </td>
                                <td><a href="<%=elem.getCertName()%>"><img src="images/download.png" title="Download"/></a></td>
                                <td><a href="CertDetail.jsp?certPath=<%=elem.getCertPath()%>">Detail</a></td>
                                <%
                                                                                                        }
                                %>

                            </tr>
                            <%
                                                                    }
                            %>
                        </table>

                        <%} else {
                        %>
                        <h1>Please log in to use this feature!</h1>
                        <%            }
                        %>
                    </div>

                    <div id="left">
                        <%@include file="leftPanel.jsp" %>
                    </div>


                    <!--content ends -->
                    <!--footer begins -->
                </div>


                <div id="footer">
                    <p>Copyright  2011.Design by Nguyen Xuan Tuan</p>
                </div>
                <div style="clear: both"></div>
            </div>

        </div>
        <!-- footer ends-->
    </body>
</html>
